package com.tubi.TreeSet;
 //如果有排序继承 Comparable<泛型>
public class Student implements  Comparable<Student>{
    private String name;
    private int chinese;
    private int math;
    private int english;

    public Student() {
    }

    public Student(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    public  int getSum(){
        return this.chinese + this.math + this.english;
    }
    @Override  //排序规则
    public int compareTo(Student o) {
        //按照总分进行排序
        int res = this.getSum() - o.getSum();
        res = res==0 ? this.getChinese() - o.getChinese() : res;
        res = res==0 ? this.getMath() - o.getMath() : res;

        //姓名不能比较所以要下民这样写
        res = res==0 ? this.getName().compareTo(getName()) : res;
        return res;
    }
}
